package platzerworld.kegeln.vo.klasse;

import platzerworld.kegeln.common.KeyValueVO;
import platzerworld.kegeln.common.adapter.EqualsUtil;
import platzerworld.kegeln.common.adapter.HashCodeUtil;


/**
 * Value-Object KlasseVO
 * 
 * @author platzerg
 */
public class KlasseVO  extends KeyValueVO {
	private static final long serialVersionUID = 3979541748513076136L;
	
	public String klasseId = "";
  
	public String name;
	
	public String schub = "100";
	public KlasseVO(){
		super();
	}
	
	public KlasseVO(long key, String klasseId, String name, String schub){
		super(key, name);
		this.klasseId = klasseId;
		this.name = name;
		this.schub = schub;
	}
	
  /**
   * Zeigt an, ob die Klasse bereits gespeichert wurde.
   * 
   * @return true, wenn die Klasse in Datenbank vorhanden ist.
   */
  public boolean istNeu() {
    return key == 0;
  }
  
  @Override
  public String toString(){
		return this.name;
  }
  
  @Override 
  public boolean equals(Object otherKlasseVO) {
	    if ( this == otherKlasseVO ) return true;
	    KlasseVO that = (KlasseVO)otherKlasseVO;

	    return EqualsUtil.areEqual(this.key, that.key);
  }
  
  @Override 
	public int hashCode() {
		 int result = HashCodeUtil.SEED;
		 result = HashCodeUtil.hash( result, key );
		 return result;
	}

	@Override
	public int compareTo(KeyValueVO otherKlasseVO) {
		final int BEFORE = -1;
	    final int EQUAL = 0;
	    final int AFTER = 1;
	    if ( this == otherKlasseVO ) return EQUAL;

	    final KlasseVO compareVO = (KlasseVO) otherKlasseVO;
	    
	    // int comparison = this.name.compareTo(compareVO.name);
	    // if ( comparison != EQUAL ) return comparison;
	    
	    if (this.key < compareVO.key) return BEFORE;
	    if (this.key > compareVO.key) return AFTER;

	    return EQUAL;
	}
  
  
}
